
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class StudentRegisterServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {

        String student_uname=request.getParameter("student_uname");
        String student_pwd=request.getParameter("student_pwd");
        String student_name=request.getParameter("student_name");
        String student_id=request.getParameter("student_id");
        
        String college_code=request.getParameter("college_code");
        String course=request.getParameter("course");
        String student_mobile=request.getParameter("mobile");
         String student_email=request.getParameter("email");
        
         response.setContentType("text/html");
         PrintWriter out=response.getWriter();

if((student_uname !="")&&(student_pwd != "")&&(student_name != "")&&(student_id != "")&&(college_code !="")&&(course !="")&&(student_mobile !="")&&(student_email !=""))
{
      Class.forName("oracle.jdbc.driver.OracleDriver");
       Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 

         Statement stmt=con.createStatement();      

         ResultSet rs = stmt.executeQuery("SELECT *FROM college_register WHERE college_code='"+college_code+"'");


         if(rs.next())

         {

         PreparedStatement pstmt1=con.prepareStatement("insert into student_login values(?,?)");
         
         pstmt1.setString(1,student_uname);
         pstmt1.setString(2,student_pwd);

         pstmt1.executeUpdate();

        
        PreparedStatement pstmt2=con.prepareStatement("insert into student_register values(?,?,?,?,?)");
         
         pstmt2.setString(1,student_name);
         pstmt2.setString(2,student_id);
         pstmt2.setString(3,college_code);
         pstmt2.setString(4,course);
         pstmt2.setString(5,student_uname);
       
         pstmt2.executeUpdate();

PreparedStatement pstmt3=con.prepareStatement("insert into student_details values(?,?,?)");
      pstmt3.setString(1,student_id);
         pstmt3.setString(2,student_mobile);
         pstmt3.setString(3,student_email);
       pstmt3.executeUpdate();
        
         }

         out.println("<html>");
     
         out.println("<body background=\"t5.jpg\"><center>");
         out.println("<div><div style='float:left'>");
out.println("<form action='index.html'>");
 out.println("<input type='submit' value='home'/></form></div>");
         out.println("<font size='4'>");
         out.println("<h2>Qualification details:</h2>");
         out.println("<form method='post' action='srs2'");
         out.println("<table width='100%' cellpadding='5' >");
         out.println("<tr><td> SSC Marks Percentage                :</td>");
         out.println("<td align='right'> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='ssc'/></td>");
         out.println("</tr>");
         out.println("<br><br>");
         out.println(" <tr align='left'>");
         out.println ("<td>   Year of passing                       :</td>"
                  + "<td align='right'> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='ssc_year'/></td></tr>");
         out.println("<br><br>");
         out.println("<tr align='left'>");
 
         out.println("<td>   Intermediate Marks Percentage          :</td>");
         out.println("<td align='right'> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='inter'/></td></tr>"); 
         out.println("<br><br>");
         out.println("<tr align='left'>");
         out.println("<td>    Year of passing                       : </td>");
         out.println("<td align='right'> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='inter_year'/></td></tr>");
         out.println("<br><br>");
         out.println("<tr><td>Graduation Marks Percentage            :</td>");
         out.println("<td align='right'> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='graduation'/></td></tr>");
         out.println("<br><br>");
         out.println("<tr><td> Year of passing                       :</td>");
         out.println("<td> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='graduation_year'/></td></tr>");
out.println("<br><br>");
out.println("<tr> <td>         PG Marks Percentage                   :</td>");
         out.println("<td align='right'> <input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='pg'/></td></tr>");


out.println("<br><br><br>");
 
out.println("<tr align='left'>");
        out.println("<td>        year of passing          :     </td>"
                + "<td align='right'><input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='pg_year'/></td></tr>");
  out.println("<br><br>");
  out.println("<tr align='left'>");
        out.println("<td>       Technical_skills         :     </td>"
                + "<td align='right'><input class=chk type='text' size='30' style='font-size:14pt; height:30px' name='technical_skills'/></td></tr>");
  out.println("<br><br>");

out.println("</table><input type='hidden' name='student_uname' value='"+student_uname+"'>");
 out.println("<input type ='hidden' name='student_id' value='"+student_id+"' /> ");
 out.println("<input type='submit' value='submit'/></form>");
 
         
         
         out.println("</font>");

         out.println("</center></body>");

         out.println("</html>");   
 
      

}
         else

       {

         out.println("<html>");
     
          out.println("<body background=\"t5.jpg\">");
  
         out.println("<font size=\"4\" color=\"white\">");
         out.println("<div><div style='float:left'>");
out.println("<form action='index.html'>");
 out.println("<input type='submit' value='home'/></form></div>");
        out.println("<br> <b><center> Registration Not Successful, due to the foowing reasons:</center>");
        out.println(" <center>1.The College with code "+college_code+" is not available </b><br>2.All fields shouid be flled<br><br>3.you may enter invalid values</center>");
  

        out.println("</font>");

         out.println("</body>");

         out.println("</html>");   
        

        }

    } 

    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 